Return to doc.sitecore.com

Valid for Sitecore 5.2, 5.3
I use sublayout via placeholder. How can I read parameters in C# code which I placed on a placeholder in Sitecore client?

 You can use the following sample code:

using Sitecore.Data.Items;
using Sitecore.Layouts;

...

public static string GetRenderingParameters(string renderingid)
{
  // convert path to ID. May cause exceptions
  renderingid = Sitecore.Context.Database.Items[renderingid].ID.ToString();

  // get current item.
  Item item = Sitecore.Context.Item;
  // get current device.
  DeviceItem device = Sitecore.Context.Device;

  // get list of rederings for the item.
  RenderingReference[] renderings;   
  renderings = item.Visualization.GetRenderings(device, true);

  // find appropriate rendering reference.
  foreach (RenderingReference reference in renderings)
  {
    if (reference.RenderingItem != null)
    {
      if (reference.RenderingItem.ID.ToString() == renderingid)
      {
        return reference.Settings.Parameters;
      }
    }
  }
  // return empty string if nothing found.
  return string.Empty;
}